/*
 * Created by JFormDesigner on Fri May 20 09:44:20 CST 2022
 */

package jw3.c7.view;

import jw3.c7.utils.DBConnection;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author Brainrain
 */
public class Register extends JFrame {
    public Register() {
        initComponents();
    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
            String sql="insert user values(?,?,?,?,?,?,?)";
            if (textField2.getText().equals("")||textField3.getText().equals("")||textField1.getText().equals("")||
                    new String(passwordField.getPassword()).equals(""))
            {
                JOptionPane.showMessageDialog(null,"注册失败");

            }else {
                DBConnection.zsg(sql,0,
                        textField2.getText(),textField3.getText(),
                        comboBox1.getSelectedIndex()+1,comboBox2.getSelectedIndex()+1,textField1.getText(),
                        new String(passwordField.getPassword()));
                JOptionPane.showMessageDialog(null,"注册成功");
            }
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        passwordField = new JPasswordField();
        button1 = new JButton();
        label4 = new JLabel();
        textField2 = new JTextField();
        label5 = new JLabel();
        textField3 = new JTextField();
        label6 = new JLabel();
        comboBox1 = new JComboBox();
        label7 = new JLabel();
        comboBox2 = new JComboBox();

        //======== this ========
        setTitle("\u4e0d\u52a8\u4ea7\u7ba1\u7406\u7cfb\u7edf");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u8bf7\u8f93\u5165\u8d26\u53f7");
        label1.setForeground(Color.white);
        contentPane.add(label1);
        label1.setBounds(190, 160, 80, 20);

        //---- label2 ----
        label2.setText("\u8bf7\u8f93\u5165\u5bc6\u7801");
        label2.setForeground(Color.white);
        contentPane.add(label2);
        label2.setBounds(193, 200, 75, 20);
        contentPane.add(textField1);
        textField1.setBounds(295, 160, 110, 30);
        contentPane.add(passwordField);
        passwordField.setBounds(295, 200, 110, 30);

        //---- button1 ----
        button1.setText("\u6ce8\u518c");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(305, 295), button1.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u8bf7\u8f93\u5165\u6635\u79f0");
        label4.setForeground(Color.white);
        contentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(200, 32), label4.getPreferredSize()));
        contentPane.add(textField2);
        textField2.setBounds(295, 25, 110, textField2.getPreferredSize().height);

        //---- label5 ----
        label5.setText("\u771f\u5b9e\u59d3\u540d");
        label5.setForeground(Color.white);
        contentPane.add(label5);
        label5.setBounds(new Rectangle(new Point(206, 67), label5.getPreferredSize()));
        contentPane.add(textField3);
        textField3.setBounds(295, 60, 110, 30);

        //---- label6 ----
        label6.setText("\u90e8\u95e8ID");
        label6.setForeground(Color.white);
        contentPane.add(label6);
        label6.setBounds(205, 110, 50, label6.getPreferredSize().height);
        contentPane.add(comboBox1);
        comboBox1.setBounds(295, 95, 110, 30);

        //---- label7 ----
        label7.setText("\u89d2\u8272ID");
        label7.setForeground(Color.white);
        contentPane.add(label7);
        label7.setBounds(new Rectangle(new Point(205, 135), label7.getPreferredSize()));
        contentPane.add(comboBox2);
        comboBox2.setBounds(295, 130, 110, 30);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        comboBox1.addItem("人事部");
        comboBox1.addItem("营销部");
        comboBox1.addItem("生产部");
        comboBox1.addItem("销售部");
        comboBox1.addItem("广告部");
        comboBox1.addItem("技术部");
        comboBox1.addItem("人力部");
        comboBox1.addItem("财务部");
        comboBox1.addItem("市场部");
        comboBox2.addItem("总经理");
        comboBox2.addItem("副总经理");
        comboBox2.addItem("人力资源总监");
        comboBox2.addItem("财务总监");
        comboBox2.addItem("营销总监");
        comboBox2.addItem("市场总监");
        comboBox2.addItem("销售总监");
        comboBox2.addItem("生产总监");
        comboBox2.addItem("运营总监");
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JPasswordField passwordField;
    private JButton button1;
    private JLabel label4;
    private JTextField textField2;
    private JLabel label5;
    private JTextField textField3;
    private JLabel label6;
    private JComboBox comboBox1;
    private JLabel label7;
    private JComboBox comboBox2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
